<template>
  <div class="app-container bg-gray">
    <el-card class="box-1">
      <div slot="header">
        <span>问卷设置</span>
      </div>
      <el-form ref="form" :model="form" label-width="120px">
        <el-form-item label="回收提醒">
          每新增<el-input v-model="form.goods_money" size="small" type="number"/>份回收，通知一次
        </el-form-item>
        <el-form-item label="通知方式">
          <el-checkbox-group v-model="form['way']">
            <el-checkbox :label="1">短信</el-checkbox>
            <el-checkbox :label="2">微信</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item>
          <el-button type="success" class="bg-green btn">保存</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        way: []
      }
    }
  },
  watch: {},
  created() {
    this.id = this.$route.query.id
  },
  methods: {
    /**
     *  增加题目
     *  接口:'user/all-list'
     */
    toAddQuestion() {
      this.form['question'].reverse()
      this.form['question'].push({
        title: '',
        type: 0,
        questionType: 0,
        optionsType: 0,
        options: [{ value: '' }]
      })
      this.form['question'].reverse()
    },

    toAddQuestionOptions(index) {
      this.form['question'][index]['options'].push({ value: '' })
    },

    toDeleteQuestionOptions(index, optionsIdx) {
      this.form['question'][index]['options'].splice(optionsIdx, 1)
    },

    toDeleteQuestion(index) {
      this.form['question'].splice(index, 1)
    },

    /**
       *  获取系统用户列表
       *  接口:'user/all-list'
       */
    getUsersList() {
      const url = 'user/all-list'
      this.$store.dispatch('GetConnect', { url }).then(res => {
        this.usersList = res.data
      }).catch(e => {
        this.$message.error(e.msg + ',请刷新或联系管理员')
      })
    },

    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const data = this.form
          data.sale_proof = data.pic_list
          const url = 'achievement/edit/' + this.id
          this.$store.dispatch('GetConnect', { url, data }).then(res => {
            this.$message.success(res.msg)
            this.$router.back(-1)
          }).catch((err) => {
            this.$message.error(err.msg)
          })
        } else {
          this.$message.error('提交失败,请检查必填项')
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="scss" type="text/scss" scoped>
  @import '../../../styles/index.scss';

  .box-1 {
    max-width: 1000px;
    margin: 0 auto;

    > div span {
      font-size: 18px;
      font-weight: 600;
      padding: 0 10px;
    }

    .el-form {
      max-width: 900px;
      .el-input{
        width: 100px;
        margin: 0 10px;
      }
    }
  }

  .btn {
    width: 20%;
    min-width: 160px;
  }

  .el-checkbox {
    margin-right: 30px;
  }

  .el-checkbox + .el-checkbox {
    margin-left: 0;
    margin-right: 30px;
  }
</style>
